<?php
defined( '_JEXEC' ) or die( 'Restricted Access' );
/**
 * @version     $Id$
 * @package     Virtuemart
 * @subpackage  GoodRelations Module
 * @copyright   Copyright (C) 2010 Alex Stolz - All rights reserved.
 * @license     LGPL
 */

global $vmLogger;
$configuration_done = 0;
$option = &JRequest::getVar('option', "");
$page = &JRequest::getVar('page', "");
$application = &JFactory::getApplication();
$document = &JFactory::getDocument();

// check if request-option is com_virtuemart
if($option=="com_virtuemart"):
	require_once(dirname(__FILE__).DS.'controller.php');
	$configuration_done = $params->get('configuration_done');
	// create an instance of the controller
	$controller = new ModSemanticWebController;
	
	// check whether the Virtuemart component is enabled or not
	if($controller->isVirtueMartEnabled()):
		if(!$page || $page=="shop.product_details"):
			// MODIFY DOCUMENT HEADER
			// get the component and page parameters
			$j_params = &$application->getParams();
			$document->setMetaData('content-type', "application/xhtml+xml; charset=utf-8", true);
		endif;
		
		// CUSTOMIZE APP ACCORDING TO USER-DEFINED PARAMETERS
		// set params also for the controller class
		$controller->setParams($params);
		// set a timeout for the files (a longer time span speeds the application up)
		$timeout = $params->get('timeout');
		$controller->setTimeout($timeout);
		// check, if configuration needs to be done
		// $vmLogger->info("config_done=".strval($configuration_done)." value=".strval("t")." timeout=".$timeout);
		if(!$configuration_done) { //!file_exists(dirname(__FILE__).DS.'mod_goodrelations.xml') || !$configuration_done) {
			require_once(dirname(__FILE__).DS.'create_manifest.php');
			$vmLogger->info('Install file for GoodRelations module was updated. Please check out the new options of the extension in the backend and if necessary confirm to finish the configuration!');
			// ping semantic web search engines
			if(strpos($params->get('ping_submission_base_uri'), JURI::base()) === false) {
    		    $controller->notifySWSE(VERSION);
    		}
		}
		else {
			if($page=="shop.product_details") {
				// template order here is very very important!! -> because product contains opening divs, datasheet closes them
				$controller->getRDFaSnippet('product');
				if($params->get('display_reviews'))
				    $controller->getRDFaSnippet('review');
				else
				    echo <<<CLOSING_DIVS
	</div>
</div>
CLOSING_DIVS;
			}
			else if(!$page) {
				$controller->getRDFaSnippet('categories');
				$controller->getRDFaSnippet('manufacturers');
				$controller->getRDFaSnippet('company');
				$controller->getRDFaSnippet('vendor');
			}
			// create sitemap, if required
			if($params->get('create_sitemap'))
				$controller->createSitemap();
		}
		
		require_once(JModuleHelper::getLayoutPath('mod_goodrelations'));
	endif;
endif;
// Virtuemart is not enabled, missing or user navigates on any site on the webpage that does not belong to Virtuemart
?>